package com.wrupple.muba.catalogs.domain;

import com.google.gwt.core.client.GWT;
import com.wrupple.muba.catalogs.client.activity.BrowsingActivity;
import com.wrupple.muba.catalogs.client.activity.CatalogActivity;
import com.wrupple.muba.common.domain.DesktopPlace;
import com.wrupple.muba.common.domain.FilterData;
import com.wrupple.vegetate.client.module.services.logic.FilterDataSerializationService;

@SuppressWarnings("serial")
public class CatalogPlace extends DesktopPlace {
	private static final String FILTER_DATA_PARAMETER = "filter";
	
	public CatalogPlace(String catalog,String entry) {
		super(BrowsingActivity.ACTIVITY_ID);
		setCatalog(catalog);
		setEntryId(entry);
		super.setName(catalog);
	}
	
	
	public CatalogPlace(DesktopPlace place) {
		super(place);
	}


	public void setEntryId(String entry) {
		super.setProperty(CatalogActivity.CATALOG_ENTRY_PARAMETER, entry);
	}

	public void setCatalog(String catalog) {
		super.setProperty(CatalogActivity.CATALOG_ID_PARAMETER, catalog);
	}

	public String getCatalog(){
		return this.getProperty(CatalogActivity.CATALOG_ID_PARAMETER);
	}
	
	public String getEntryId(){
		return this.getProperty(CatalogActivity.CATALOG_ENTRY_PARAMETER);
	}
	
	public void setFilter(String filter){
		super.setProperty(FILTER_DATA_PARAMETER, filter);
	}
	
	public String getFilter(){
		return super.getProperty(FILTER_DATA_PARAMETER);
	}
	
	public FilterData getFilterData(FilterDataSerializationService service){
		try {
			return service.deserialize(getFilter());
		} catch (Exception e) {
			GWT.log("Failed to deserialize filter data and default filters will be used",e);
			return new FilterData();
		}
	}
}
